package dbtools.structures;

import java.sql.SQLException;

import dbtools.DBTransaction;

public class DBFieldCounter extends DBFieldLong{

	private static final long serialVersionUID = 1L;
	private String counterName;
	private long initialValue;

	public DBFieldCounter(String counterName, long initialValue){
		this.counterName = counterName;
		this.initialValue = initialValue;
	}
	
	@Override
	public void beforeInsert(DBTransaction transaction) {
		long counter;
		try {
			counter = transaction.getDatabase().getCounterLong(counterName, initialValue);
			setValue(counter);
		} catch (SQLException e) {
			throw new Error(e);
		}
	}
	

}
